package com.jewaton.authmanage.base;

import org.springframework.security.core.context.SecurityContextHolder;

import com.jewaton.authmanage.pojo.UserInfo;


public class BaseController {
	
	/**
	 * 通过Spring Security获取当前登录用户
	 * @return
	 */
	protected UserInfo getSessionUser() {
		UserInfo user = (UserInfo) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();
		return user;
	}
	
	/**
	 * 通过Spring Security获取当前登录用户名
	 * @return
	 */
	protected String getSessionUserName() {
		UserInfo user = this.getSessionUser();
		if(user!=null) return user.getUsername();
		return "";
	}

}
